package kr.couponplay.android.domain.deal;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import android.location.Location;
import kr.couponplay.android.support.StringUtils;

public class QueryMaker {
	public String baseQuery(String sid, int mainCategoryId, int subCategoryId, String query, int offset) {
		try {
			StringBuffer queryParams = new StringBuffer();
			queryParams.append("?sid=" + StringUtils.trimToEmpty(sid));
			queryParams.append("&offset=" + offset);
			queryParams.append("&query=" + URLEncoder.encode(StringUtils.trimToEmpty(query), "UTF-8"));
			queryParams.append("&mainCategoryId=" + mainCategoryId);
			queryParams.append("&subCategoryId=" + subCategoryId);
			return queryParams.toString();
		} catch (UnsupportedEncodingException e) {
			throw new IllegalStateException(e.getMessage(), e);
		}
	}	
	
	public String locationQuery(String url, Location location) {
		if (location == null) {
			return url;
		}
		url = url + "&nowLat=" + location.getLatitude();
		url = url + "&nowLon=" + location.getLongitude();
		return url;
	}	
}
